function alertTips(content) {
    alert(content)
}

function checkIsNull(value) {
    return value === "" || value === undefined || value === null;
}

function checkIsNotNull(value) {
    return value !== "" && value !== undefined && value !== null;
}

//获取时间戳
function getTimestamp() {
    return "img_"+new Date().getTime();
}

//根据值删除Array元素
Array.prototype.removeByValue = function(val) {
    for(var i=0; i<this.length; i++) {
        if(this[i] === val) {
            this.splice(i, 1);
            break;
        }
    }
};

//清除空的Array
function ClearNullArr(arr){
    for(var i=0,len=arr.length;i<len;i++){
        if(!arr[i]||arr[i]===''||arr[i] === undefined){
            arr.splice(i,1);
            len--;
            i--;
        }
    }
    return arr;
}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

function getNowFormatDateTime() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}

//发送验证码
function sendSmsCode(mobile,sms_type) {
    if(checkIsNull(mobile)){
        alertTips("请填写手机号！");
        return false;
    }
    if(!(/^1[34578]\d{9}$/.test(mobile))){
        alert("手机号格式不正确，请重填");
        return false;
    }
    $.ajax({
        type: "post",
        url: '/sendSmsCode.do',
        dataType: "json",
        data: {
            'mobile' : mobile,
            'smsType' : sms_type
        },
        success: function(resp){
            console.log(resp);
            if(resp.result==="success"){
                setResendTime();
            }else{
                getCodeAgain();
            }
        }
    });
}


var timer ;
var countdown=60;
var reGetCode="重新获取";
var getCode="发送验证码";

function setResendTime() {
    if (countdown === 0) {
        getCodeAgain();
        return ;
    } else {
        $("#mobile").attr("readonly","readonly");
        $("#send-sms-code").attr("disabled","disabled");
        $("#send-sms-code").val(reGetCode+"("+countdown+"s)");
        countdown--;
    }
    timer = setTimeout(function(){setResendTime();
    } ,1000)
}

function getCodeAgain(){
    $("#mobile").removeAttr("readonly");
    $('#send-sms-code').removeAttr("disabled");
    $('#send-sms-code').attr("onclick","getSmsCode()");
    $("#send-sms-code").val(getCode);
    countdown = 60;
    clearTimeout(timer);
}

